package com.newatlanta.commons.vfs.provider.gae.jar;

import java.io.InputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.net.URI;
import java.util.List;

import org.apache.commons.vfs.FileContent;
import org.apache.commons.vfs.FileName;
import org.apache.commons.vfs.FileObject;
import org.apache.commons.vfs.FileSelector;
import org.apache.commons.vfs.FileSystem;
import org.apache.commons.vfs.FileSystemException;
import org.apache.commons.vfs.FileType;
import org.apache.commons.vfs.NameScope;
import org.apache.commons.vfs.RandomAccessContent;
import org.apache.commons.vfs.operations.FileOperations;
import org.apache.commons.vfs.provider.AbstractFileSystem;
import org.apache.commons.vfs.util.RandomAccessMode;

import com.newatlanta.commons.vfs.provider.gae.GaeFileObject;


@SuppressWarnings("serial")
public class GaeJarFileObjectAdapter implements FileObject , Serializable{

	 final GaeFileObject delegate;
	 final transient GaeJarFileSystem fs;
	
	public GaeJarFileObjectAdapter(GaeFileObject delegate) throws FileSystemException {
		super();
		this.delegate = delegate;
		
		
		//fs = new GaeJarFileSystem( new SimpleFileName("", "", FileType.FOLDER), delegate, null);
		fs = new GaeJarFileSystem( delegate.getName(), delegate, null);
		
		fs.setContext( ((AbstractFileSystem)delegate.getFileSystem()).getContext());
		
		fs.init();
	}

	public void setCombinedLocal(boolean b) {
		delegate.setCombinedLocal(b);
	}

	public int getBlockSize() {
		return delegate.getBlockSize();
	}

	public void setBlockSize(int size) throws FileSystemException {
		delegate.setBlockSize(size);
	}

	public int hashCode() {
		return delegate.hashCode();
	}

	public boolean equals(Object obj) {
		return delegate.equals(obj);
	}

	public int compareTo(Object obj) {
		return delegate.compareTo(obj);
	}

	public FileObject[] getChildren() throws FileSystemException {
		return delegate.getChildren();
	}

	public String toString() {
		return delegate.toString();
	}

	public FileName getName() {
		return delegate.getName();
	}

	public FileSystem getFileSystem() {
		
		return fs;
	}

	public URI getURI() throws FileSystemException {
		return delegate.getURI();
	}

	public boolean exists() throws FileSystemException {
		return delegate.exists();
	}

	public FileType getType() throws FileSystemException {
		return delegate.getType();
	}

	public boolean isHidden() throws FileSystemException {
		return delegate.isHidden();
	}

	public boolean isReadable() throws FileSystemException {
		return delegate.isReadable();
	}

	public boolean isWriteable() throws FileSystemException {
		return delegate.isWriteable();
	}

	public FileObject getParent() throws FileSystemException {
		return delegate.getParent();
	}

	public FileObject getChild(String name) throws FileSystemException {
		return delegate.getChild(name);
	}

	public FileObject resolveFile(String name, NameScope scope)
			throws FileSystemException {
		
		return fs.resolveFile(name);
	}

	public FileObject resolveFile(String path) throws FileSystemException {
		return delegate.resolveFile(path);
	}

	public boolean delete() throws FileSystemException {
		return delegate.delete();
	}

	public int delete(FileSelector selector) throws FileSystemException {
		return delegate.delete(selector);
	}

	public void createFile() throws FileSystemException {
		delegate.createFile();
	}

	public void createFolder() throws FileSystemException {
		delegate.createFolder();
	}

	public void copyFrom(FileObject file, FileSelector selector)
			throws FileSystemException {
		delegate.copyFrom(file, selector);
	}

	public void moveTo(FileObject destFile) throws FileSystemException {
		delegate.moveTo(destFile);
	}

	public boolean canRenameTo(FileObject newfile) {
		return delegate.canRenameTo(newfile);
	}

	public FileObject[] findFiles(FileSelector selector)
			throws FileSystemException {
		return delegate.findFiles(selector);
	}

	public FileContent getContent() throws FileSystemException {
		return delegate.getContent();
	}

	public void refresh() throws FileSystemException {
		delegate.refresh();
	}

	public void close() throws FileSystemException {
		delegate.close();
	}

	public InputStream getInputStream() throws FileSystemException {
		return delegate.getInputStream();
	}

	public RandomAccessContent getRandomAccessContent(RandomAccessMode mode)
			throws FileSystemException {
		return delegate.getRandomAccessContent(mode);
	}

	public OutputStream getOutputStream() throws FileSystemException {
		return delegate.getOutputStream();
	}

	public OutputStream getOutputStream(boolean bAppend)
			throws FileSystemException {
		return delegate.getOutputStream(bAppend);
	}

	public void findFiles(FileSelector selector, boolean depthwise,
			List selected) throws FileSystemException {
		delegate.findFiles(selector, depthwise, selected);
	}

	public boolean isContentOpen() {
		return delegate.isContentOpen();
	}

	public boolean isAttached() {
		return delegate.isAttached();
	}

	public void holdObject(Object strongRef) {
		delegate.holdObject(strongRef);
	}

	public FileOperations getFileOperations() throws FileSystemException {
		return delegate.getFileOperations();
	}
	

}
